package io.shallwe.stovingoven;

import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Record;
import io.shallwe.common.controller.BaseController;
import io.shallwe.common.model.Account;
import io.shallwe.common.model.StovingOven;

/**
 * 烘干炉温度控制
 * 连续多个电泳框为空，第一个电泳框出烘干炉开始降温
 * 连续多个空箱第一个有料电泳框进入后开始升温
 * @author 王小伟
 * @date 2019/7/10 11:09:01
 **/
public class StovingOvenTemperatureController extends BaseController {

    @Inject
    StovingOvenTemperatureService service;

    /**
     * 打开配置页面
     */
    public void index(){
        StovingOven stovingOven = service.getStovingOven();
        Account account = Account.dao.findById(stovingOven.getChangeBy());
        Record record = stovingOven.toRecord();
        record.set("changeUser",account.getRealName());
        set("stovingOven",record);
        render("index.html");
    }

    /**
     * 获取配置信息
     */
    public void getConfig(){
        StovingOven stovingOven = service.getStovingOven();
        Ret ret=Ret.ok("stovingOven",stovingOven);
        renderJson(ret);
    }

    /**
     * 保存配置信息
     */
    @Before(StovingOvenTemperatureValidator.class)
    public void save(){
        StovingOven stovingOven = getBean(StovingOven.class, "stovingOven", true);
        Account loginAccount = getLoginAccount();
        Ret ret = service.saveStovingOven(stovingOven, loginAccount);
        renderJson(ret);
    }
}
